package domfarr;

import java.util.Collection;
import java.util.Collections;

import org.junit.Test;

// this does the null throw npe: because it calls the iterator method.
// therefore always check foreach object for null before loop
// this is a pretty dump test case, but sometimes my brain hurts. :)
public class QuickForEach {

	@SuppressWarnings("unchecked")
	private Collection emptyCollection = Collections.emptyList();

	@SuppressWarnings("unchecked")
	private Collection nullCollection;
	
	@Test
	public void testEmptyCollectionInForEach() {
		loop(emptyCollection);
	}
	
	@Test(expected = NullPointerException.class)
	public void testNullCollectionInForEach() {
		loop(nullCollection);
	}
	
	@Test
	public void testCheckingNullCollectionBeforeCallingForEach() {
		if(nullCollection != null) {
			loop(nullCollection);			
		}
	}
	
	@SuppressWarnings("unchecked")
	private void loop(Collection collection) {			
		for(@SuppressWarnings("unused") Object o : collection) {
		}
	}
}
